package com.hbxx.lotteryapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbxx.lotteryapp.commons.Result;
import com.hbxx.lotteryapp.commons.TokenService;
import com.hbxx.lotteryapp.entity.LoginUser;
import com.hbxx.lotteryapp.entity.TRechargeRecord;
import com.hbxx.lotteryapp.mapper.RechargeRecordMapper;
import com.hbxx.lotteryapp.service.IRechargeRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Tonny
 * @since 2022-06-07
 */
@Service
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordMapper, TRechargeRecord> implements IRechargeRecordService {

    @Resource
    RechargeRecordMapper rechargeRecordMapper;
    @Resource
    private TokenService tokenService;

    /**
     * 充值记录分页查询
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @Override
    public Result queryRechargePage(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        LoginUser loginUser = tokenService.getLoginUser(request);
        String openId = loginUser.getOpenId();
        QueryWrapper<TRechargeRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id",openId).orderByDesc("recharge_time");
        Page<TRechargeRecord> recordPage = new Page<>(pageNum, pageSize);
        Page<TRechargeRecord> tRechargeRecordPage = rechargeRecordMapper.selectPage(recordPage, queryWrapper);
        return Result.SUCCESS(tRechargeRecordPage);
    }
}
